package com.gitee.dupe.log.controller;

import com.gitee.dolt.annotation.security.PreAuth;
import com.gitee.dolt.boot.controller.QueryController;
import com.gitee.dolt.boot.controller.SaveController;
import com.gitee.dolt.boot.controller.SuperSimpleController;
import com.gitee.dolt.core.base.Result;
import com.gitee.dolt.core.context.ContextUtil;
import com.gitee.dolt.model.RemoteData;
import com.gitee.dolt.utils.BeanUtils;
import com.gitee.dupe.log.dto.OptLogSaveDTO;
import com.gitee.dupe.log.entity.OptLog;
import com.gitee.dupe.log.service.IOptLogService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2021-01-05
 */
@RestController
@RequestMapping("/b/opt-log")
@Validated
@Api(value = "OptLog", tags = "操作日志")
@PreAuth(replace = "b:optLog:")
public class OptLogController extends SuperSimpleController<OptLog, IOptLogService>
        implements QueryController<OptLog, Long, OptLog>, SaveController<OptLog, OptLogSaveDTO> {

    @Override
    public Result handlerSave(OptLogSaveDTO optLogSaveDTO) {
        OptLog optLog = BeanUtils.toBean(optLogSaveDTO, OptLog.class);
        optLog.setUserId(new RemoteData<>(ContextUtil.getUserId()));
        baseService.save(optLog);
        return Result.ok();
    }
}
